<script setup>
import { RouterLink, RouterView, useRouter } from 'vue-router'
import { ElContainer, ElHeader, ElAside, ElMain, ElMenu, ElMenuItem, ElIcon, ElButton } from 'element-plus'
import { Calendar, User, TrendCharts, Clock, Document, Setting } from '@element-plus/icons-vue'
import { ref, computed } from 'vue'

const router = useRouter()
const username = computed(() => localStorage.getItem('username') || '用户')

const handleLogout = () => {
  localStorage.removeItem('token')
  localStorage.removeItem('username')
  router.push('/login')
}

const isLoggedIn = computed(() => !!localStorage.getItem('token'))
</script>

<template>
  <div v-if="!isLoggedIn" class="h-screen">
    <RouterView />
  </div>
  
  <el-container v-else class="h-screen">
    <el-header class="bg-blue-600 text-white flex items-center justify-between">
      <div class="text-xl font-bold">智慧社区健康管理平台</div>
      <div class="flex items-center space-x-4">
        <span>欢迎，{{ username }}</span>
        <el-button type="primary" link @click="handleLogout">退出登录</el-button>
      </div>
    </el-header>
    
    <el-container>
      <el-aside width="200px" class="bg-gray-100">
        <el-menu
          default-active="1"
          class="h-full"
          router
        >
          <el-menu-item index="/">
            <el-icon><TrendCharts /></el-icon>
            <span>健康概览</span>
          </el-menu-item>
          <el-menu-item index="/health-data">
            <el-icon><Document /></el-icon>
            <span>健康数据</span>
          </el-menu-item>
          <el-menu-item index="/reminders">
            <el-icon><Calendar /></el-icon>
            <span>健康提醒</span>
          </el-menu-item>
          <el-menu-item index="/profile">
            <el-icon><User /></el-icon>
            <span>个人档案</span>
          </el-menu-item>
          <el-menu-item index="/health-report">
            <el-icon><Document /></el-icon>
            <span>健康报告</span>
          </el-menu-item>
          <el-menu-item index="/reminder-settings">
            <el-icon><Setting /></el-icon>
            <span>提醒设置</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      
      <el-main class="bg-gray-50">
        <RouterView />
      </el-main>
    </el-container>
  </el-container>
</template>

<style scoped>
/* 自定义样式 */
</style>
